<div [@routerTransition]>
    <div class="content d-flex flex-column flex-column-fluid">
        <sub-header [title]="'QuestionManage' | localize" [description]="'QuestionManage' | localize">
            <div role="actions">
                <div class="btn-group dropdown" dropdown>
                    <button class="btn btn-primary dropdown-toggle icon-piliangcaozuo" type="button" id="applyButton"
                        data-toggle="dropdown" dropdownToggle aria-haspopup="true" aria-expanded="false">
                        {{l('batchOperation')}}
                    </button>
                    <div class="dropdown-menu" *dropdownMenu aria-labelledby="applyButton" x-placement="bottom-start">
                        <a class="dropdown-item icon-shangxian1" (click)="online()">
                            {{l('onlineBatch')}}
                        </a>
                        <a class="dropdown-item icon-xiaxian1" (click)="offline()">
                            {{l('offlineBatch')}}
                        </a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item icon-fabu1" (click)="publishToNaire()"
                            *ngIf="isGranted('Pages.Tenant.Question.Publish')">
                            {{l('publishToNaire')}}
                        </a>
                        <a class="dropdown-item icon-icon-test" (click)="deleteBatch()"
                            *ngIf="isGranted('Pages.Tenant.Question.Delete')">
                            {{l('deleteBatch')}}
                        </a>
                    </div>
                </div>
                <button class="btn btn-primary" (click)="goImport()" *ngIf="isGranted('Pages.Tenant.Question.Create')">
                    <i class="icon-excel"></i> {{l('import')}} </button>
                <button class="btn btn-primary" (click)="createQuestion()"
                    *ngIf="isGranted('Pages.Tenant.Question.Create')">
                    <i class="fa fa-plus"></i>
                    {{l("CreateQuestion")}}</button>
            </div>
        </sub-header>

        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">

                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div class="row align-items-center mb-4">
                                <div class="col-3">
                                    <div class="form-group m-form__group align-items-center">
                                        <label>{{l('title')}}</label>
                                        <div class="input-group">
                                            <input (keyup.enter)="getQuestion()" [(ngModel)]="filterText"
                                                name="filterText" autoFocus class="form-control m-input"
                                                [placeholder]="l('SearchWithThreeDot')" type="text">
                                        </div>
                                    </div>
                                </div>

                                <div class="col-2">
                                    <div class="form-group m-form__group align-items-center">
                                        <label>{{l('type')}}</label>
                                        <div class="input-group">
                                            <select class="form-control" [(ngModel)]="type" name="type">
                                                <option value="">{{l('All')}}</option>
                                                <option value="0">{{l('oneChoose')}}</option>
                                                <option value="1">{{l('multiChoose')}}</option>
                                                <option value="2">{{l('text')}}</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-2">
                                    <div class="form-group m-form__group align-items-center">
                                        <label>{{l('tags')}}</label>
                                        <div class="input-group">
                                            <select class="form-control" [(ngModel)]="tagFilter" name="type">
                                                <option value="">{{l('AllTags')}}</option>
                                                <option [value]="tag.id" *ngFor="let tag of tags">{{tag.value}}
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-2">
                                    <div class="form-group m-form__group align-items-center">
                                        <label>&nbsp;</label>
                                        <div class="input-group">
                                            <button type="button" class="btn btn-primary"
                                                [buttonBusy]="primengTableHelper.isLoading" (click)="getQuestion()">
                                                <i class="la la-refresh"></i>
                                                {{l("search")}}
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <!-- 
                                    <div class="col-3">
                                        <div class="form-group kt-form__group align-items-center">
                                            <label>{{l('tags')}}</label>
                                            <div class="input-group">
                                                <select #TagCombobox class="form-control" [(ngModel)]="tagFilter"
                                                    (ngModelChange)="getQuestion()" name="belongStore"
                                                    [attr.data-live-search]="true" jq-plugin="selectpicker">
                                                    <option value="">{{l('AllTags')}}</option>
                                                    <option [value]="tag.id" *ngFor="let tag of tags">{{tag.value}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div> -->


                                <!-- <div class="col-2">
                                        <div class="form-group kt-form__group align-items-center">
                                            <label>{{l('IsEnabled')}}</label>
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="isTemplate" (ngModelChange)="getQuestion()"
                                                    name="metaTypeSelect2">
                                                    <option value="">{{l('All')}}</option>
                                                    <option value="1">{{l('On')}}</option>
                                                    <option value="2">{{l('Off')}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div> -->
                            </div>

                        </form>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-Datatable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <!-- resizableColumns="primengTableHelper.resizableColumns" -->
                            <p-table #dataTable (onLazyLoad)="getQuestion($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                [(selection)]="questionPublishList" [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width:10%">{{l('Actions')}}</th>
                                        <th style="width: 5.0em">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th style="width:5%">{{l('RecordId')}}</th>
                                        <th>{{l('title')}}</th>
                                        <th style="width:10%" pSortableColumn="score">{{l('score')}}
                                            <p-sortIcon field="score"></p-sortIcon>
                                        </th>
                                        <th style="width:10%">{{l('type')}}</th>
                                        <!-- <th style="width:10%">{{l('questionScoreType')}}</th> -->
                                        <th>{{l('answer')}}</th>

                                        <th>{{l('tags')}}</th>
                                        <!-- <th pSortableColumn="endDate">{{l('createTime')}}
                                            <p-sortIcon field="endDate"></p-sortIcon>
                                        </th> -->
                                        <th style="width:10%">{{l('Status')}}</th>
                                    </tr>
                                </ng-template>

                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td>
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li *ngIf="isGranted('Pages.Tenant.Question.Edit')">
                                                        <a (click)="editQuestion(record)"
                                                            class="icon-bianji dropdown-item">{{l('Edit')}}</a>
                                                    </li>
                                                    <li *ngIf="isGranted('Pages.Tenant.Question.Delete')">
                                                        <a (click)="deleteQuestion(record)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td>
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td>
                                        <td> {{transIndex(i)}}</td>
                                        <td>
                                            <span>{{record.title}}</span>
                                        </td>

                                        <!-- <td>
                                            <span *ngIf="record.questionScoreType==0">{{l('PartialScore')}}</span>
                                            <span *ngIf="record.questionScoreType==1">{{l('FullScore')}}</span>
                                        </td> -->
                                        <td>
                                            <span>{{record.score}}</span>
                                        </td>
                                        <td>
                                            <span *ngIf="record.type==0">{{l('oneChoose')}}</span>
                                            <span *ngIf="record.type==1">{{l('multiChoose')}}</span>
                                            <span *ngIf="record.type==2">{{l('text')}}</span>
                                        </td>
                                        <td>
                                            <span *ngIf="record.type!=2" style="line-height:1rem;">
                                                <span *ngFor="let item of record.questionItems">
                                                    <span *ngIf="item.isAnswer">
                                                        <b *ngIf="item.prefix">{{item.prefix}}:</b>
                                                        {{item.content}}&nbsp;
                                                    </span>
                                                </span>
                                            </span>
                                            <span *ngIf="record.type==2">{{record.answer}}</span>
                                        </td>
                                        <td>
                                            <span *ngFor="let tag of record.tags"
                                                class="label label-dark label-inline">
                                                {{tag.name}}
                                            </span>
                                            <span *ngIf="!record.tags||record.tags.length==0">
                                                {{EmptyTdText}}
                                            </span>
                                        </td>
                                        <!-- <td>{{record.endDate| date : "yyyy/MM/dd"}}</td> -->
                                        <td>
                                            <span *ngIf="record.enabled"
                                                class="label label-success label-inline">{{l("On")}}</span>
                                            <span *ngIf="!record.enabled"
                                                class="label label-dark label-inline">{{l("Off")}}</span>
                                        </td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="8">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/productHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getQuestion($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>

                    <div [ngClass]="{'hide':!toPublish,'float_panel':true,'beautyScroll':true}"
                        [ngStyle]="{'height':avalibleHeight}" *ngIf="isGranted('Pages.Tenant.Question.Edit')">
                        <div class="panel_head">
                            <h3>{{l('publishToNaire')}}</h3>
                            <div class="text-right x">
                                <button (click)="toPublish=!toPublish">
                                    <i class="icon-close"></i>
                                </button>
                            </div>
                        </div>
                        <div class="panel_body">
                            <!-- <form (ngSubmit)="doPublishCoupon()" name="publishConForm"> -->
                            <form (ngSubmit)="doPublishQuestion()" name="publishConForm">
                                <div class="form-group">
                                    <div class="radio-inline">
                                        <label class="radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="add">
                                            {{l('append')}}
                                            <span></span>
                                        </label>
                                        <label class="radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="update">
                                            {{l('update')}}
                                            <span></span>
                                        </label>
                                        <label class="radio">
                                            <input type="radio" name="publishType" [(ngModel)]="publishType"
                                                value="delete">
                                            {{l('withdraw')}}
                                            <span></span>
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group">
                                        <input [(ngModel)]="treeFilter" name="treeFilterText" autoFocus
                                            class="form-control m-input" (keydown.enter)="filterTree($event)"
                                            [placeholder]="l('SearchWithThreeDot')" type="text">
                                        <span class="input-group-btn">
                                            <button class="btn btn-primary" type="button" (click)="filterTree()">
                                                <i class="icon-sousuo-sousuo"></i>
                                            </button>
                                        </span>
                                    </div>
                                </div>

                                <div class="form-group beautyScroll"
                                    [ngStyle]="{'max-height':'calc('+avalibleHeight+' - 253px)','padding-left':'20px'}">
                                    <app-my-tree #myTree [config]="{'showId':true,'name':'name'}" [(items)]="paperTree">
                                    </app-my-tree>
                                    <h3 *ngIf="!paperTree||paperTree.length==0">{{l('NoData')}}</h3>
                                </div>
                                <div class="form-group text-right">
                                    <button *ngIf="paperTree&&paperTree.length" type="submit"
                                        class="btn btn-primary">{{l('Publish')}}</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <questionModal #questionModal (modalSave)="getQuestion()"></questionModal>
    </div>

</div>